import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 0,
    message: '欢迎回家'
  },
  mutations: {
    increment(state) {
      state.count++
    },
    decrement(state) {
      state.count--
    },
    updateMessage(state, newMessage) {
      state.message = newMessage
    }
  },
  actions: {
    asyncUpdateMessage({ commit }, newMessage) {
      // 模拟异步操作
      setTimeout(() => {
        commit('updateMessage', newMessage)
      }, 1000)
    }
  },
  getters: {
    doubleCount(state) {
      return state.count * 2
    }
  },
  modules: {
    // 可以在这里添加模块
  }
})
